package com.xm.shop.app.api.controller;

import com.github.pagehelper.PageInfo;
import com.xm.shop.pojo.constants.Constants;
import com.xm.shop.pojo.entity.GoodInfo;
import com.xm.shop.pojo.entity.User;
import com.xm.shop.pojo.vo.RespResult;
import com.xm.shop.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/goods")
@Api(tags = "商品业务接口")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    //返回结果将被装换为json
    @ResponseBody
    @RequestMapping(value = "/collection", method = RequestMethod.POST)
    @ApiOperation(value = "收藏夹接口",notes = "调用当前方法的注意事项")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "pageIndex",value = "当前页面total",required =true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "pageSize",value = "页面显示数量",required =true,dataType = "String")

    })
    public RespResult info(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize, HttpServletRequest request) {
        HttpSession session1 = request.getSession();
        User loginUser =(User) session1.getAttribute(Constants.SESSION_KEY_LOGIN_USER);
        PageInfo<GoodInfo> goodInfoPageInfo = goodsService.selectGoodsByUser(pageIndex, pageSize, loginUser.getUserId());
        RespResult respResult = new RespResult<>();
        respResult.setCode(goodInfoPageInfo.getPages());
        respResult.setData(goodInfoPageInfo.getList());
        return  respResult;
    }



}
